// 自己选择的路，跪着也要走完。朋友们，虽然这个世界日益浮躁起来,只
// 要能够为了当时纯粹的梦想和感动坚持努力下去，不管其它人怎么样,我
// 们也能够保持自己的本色走下去。                      ——AKPower
#include <iostream>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <vector>
#include <map>
#include <queue>
#include <cstdio>
#include <string>
#include <stack>
#include <set>
#define IOS ios::sync_with_stdio(false), cin.tie(0)
using namespace std;
typedef long long ll;
map<string,ll> mp;

int main()
{
    IOS;
    mp["Beijing"]=8;
    mp["Washington"]=-5;
    mp["London"]=0;
    mp["Moscow"]=3;
    ll t;
    ll cnt=1;
    scanf("%lld",&t);
    while(t--){
        ll h,m;
        char flag[20],c1[20],c2[20];
        // flag.resize(20);
        // c1.resize(20);
        // c2.resize(20);
        scanf("%lld:%2lld %s",&h,&m,flag);
        scanf("%s",c1);
        scanf("%s",c2);
        ll k=mp[c2]-mp[c1];
        printf("Case %lld: ",cnt++);
        bool kua1=false;
        bool kua2=false;
        if(k>0){
            while(k--){
                h++;
                if(h==12){
                    if(strcmp(flag,"AM")==0){strcpy(flag,"PM");}
                    else {strcpy(flag,"AM");kua1=true;}
                }
                if(h>12){
                    h-=12;
                }
            }
        }
        else {
            k=0-k;
            while(k--){
                h--;
                if(h<=0){
                    h=12;
                }
                if(h==11){
                    if(strcmp(flag,"AM")==0){strcpy(flag,"PM");kua2=true;}
                    else strcpy(flag,"AM");
                }
            }
        }
        if(kua1)
            printf("Tomorrow %lld:%02lld %s\n",h,m,flag);
        else if(kua2){
            printf("Yesterday %lld:%02lld %s\n",h,m,flag);
        }
        else {
            printf("Today %lld:%02lld %s\n",h,m,flag);
        }
    }
    getchar();
    getchar();
    return 0;
}
